/*
    SDL - Simple DirectMedia Layer
    Copyright (C) 1997-2009 Sam Lantinga

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

    Sam Lantinga
    slouken@libsdl.org
*/
#include "SDL_config.h"

#if defined(SDL_JOYSTICK_CELL)

#include "../SDL_sysjoystick.h"

/* Pad functions */
void			CELL_PAD_Init								();
void			CELL_PAD_SetOpen							(SDL_Joystick* aJoystick, uint32_t aIndex, uint32_t aState);
void			CELL_PAD_JOYSTICK_Process					(SDL_Joystick* aJoystick, uint32_t aIndex);

/* Notice: The joystick driver is tightly coupled to the video driver. You will not get any events without initializing the video system. */

/* Simpletons */
int				SDL_SYS_JoystickInit						(void)						{return 4;}
void			SDL_SYS_JoystickClose						(SDL_Joystick *joystick)	{CELL_PAD_SetOpen(0, joystick->index, 0);}
void			SDL_SYS_JoystickQuit						(void)						{}
void			SDL_SYS_JoystickUpdate						(SDL_Joystick *joystick)	{CELL_PAD_JOYSTICK_Process(joystick, joystick->index);}

/* Function to open a joystick for use. */
int				SDL_SYS_JoystickOpen						(SDL_Joystick *joystick)
{
	/* check sanity */
	if(!joystick || joystick->index >= 4)
	{
		SDL_SetError("Index out of range");
		return -1;
	}

	CELL_PAD_SetOpen(joystick, joystick->index, 1);

	joystick->nbuttons = 16;
	joystick->nhats = 0;
	joystick->nballs = 0;
	joystick->naxes = 4;
	return(0);
}

const char*		SDL_SYS_JoystickName						(int index)
{
	static char NameBuffer[256];

	snprintf(NameBuffer, 256, "PAD %d\n", index + 1);

	return NameBuffer;
}

#endif /* SDL_JOYSTICK_CELL */

